# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     request_data_parse.py
    Description:   
 -------------------------------------------------
 """

from apitesting.common.util.logger import Log
from apitesting.src.models.test_suite.config_model import ConfigModel
from apitesting.src.models import TestSteps


class RequestDataParse:
    def __init__(self, case_step_data: dict, request_engin: str) -> None:
        """

        :param case_step_data: dict[config: xxx, test_steps: xxx]
        :param request_engin:
        """
        self.check_config(case_step_data["config"])
        self.test_step = self.check_test_step(case_step_data["test_steps"])

    @staticmethod
    def check_config(config: dict) -> ConfigModel | dict:
        """
        检查配置参数

        :param config:
        :return:
        """
        try:
            config_model = ConfigModel(**config)
        except Exception as e:
            Log.error(f"配置参数(config)错误: {e}")
            raise e
        else:
            return config_model

    @staticmethod
    def check_test_step(test_step: dict) -> dict | TestSteps:
        """
        检查测试步骤参数

        :param:
        """
        try:
            TestSteps(**test_step)
        except Exception as e:
            Log.error(f"测试步骤参数(test_steps)错误: {e}")
            raise e
        else:
            return test_step

    def get_headers(self):
        try:
            headers = self.test_step.request.headers
        except Exception as e:
            Log.error(f"获取请求头参数(headers)错误: {e}")
            raise e
        else:
            return headers
